package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.Refund;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午3:39 周二
 * @Description: 数据访问层接口
 *  */


 @Mapper
@Repository
public interface RefundMapper {
 //id查询
 @Select("SELECT " +
         "a.id, " +
         "a.order_id, " +
         "a.user_id, " +
         "a.reason, " +
         "a.description, " +
         "a.status, " +
         "b.username, " +
         "c.total_amount, " +
         "a.create_time " +
         "FROM refund a " +
         "JOIN user b ON a.user_id = b.id " +
         "JOIN `order` c ON a.order_id = c.id " +
         "WHERE a.id = #{id}")
 Refund select(int id);
 //user_id查询
 @Select("SELECT " +
         "a.id, " +
         "a.order_id, " +
         "a.user_id, " +
         "a.reason, " +
         "a.description, " +
         "a.status, " +
         "b.username, " +
         "c.total_amount, " +
         "a.create_time " +
         "FROM refund a " +
         "JOIN user b ON a.user_id = b.id " +
         "JOIN `order` c ON a.order_id = c.id " +
         "WHERE a.user_id = #{user_id}")
 List<Refund> selectuser_id(int user_id);
 //查询所有
 @Select("SELECT " +
         "a.id, " +
         "a.order_id, " +
         "a.user_id, " +
         "a.reason, " +
         "a.description, " +
         "a.status, " +
         "b.username, " +
         "c.total_amount, " +
         "a.create_time " +
         "FROM refund a " +
         "JOIN user b ON a.user_id = b.id " +
         "JOIN `order` c ON a.order_id = c.id ")
 List<Refund> findAll();
 //添加
 @Insert("insert into refund(order_id,user_id,reason,description,status,create_time,update_time)values(#{order_id},#{user_id},#{reason},#{description},#{status},now(),now());")
 int add(Refund refund);
 //删除
 @Delete("delete from refund where id=#{id};")
 int delete(int id);
 //修改数据
 @Update("UPDATE refund SET order_id=#{order_id},user_id=#{user_id},reason=#{reason},description=#{description},status=#{status},update_time=now() where id= #{id};")
 int update(Refund refund);
}
